<?php
require_once("db_connect.php");

function store_players($players)
{
    foreach($players as $player)
    {
        $name = $player->getName();
        $class = $player->getClass();
        $race = $player->getRace();

        $sql = "SELECT * FROM dkp_players WHERE name='$name'";
        $noplayer = true;

        $result = mysql_query($sql);

        if($result)
        {
            if(mysql_num_rows($result) > 0)
            {
                $noplayer = false;
            }

            @mysql_free_result($result);
        }
        else
        {
            die("Query failed" . mysql_error());
        }

        if($noplayer)
        {

            $sql = "INSERT INTO dkp_players(name, class, race) VALUES('$name', '$class', '$race')";

            $result = mysql_query($sql);

            if($result)
            {
                @mysql_free_result($result);
            }
            else
            {
                die("Query failed" . mysql_error());
            }
        }
    }
}
?>